package com.deft.design.abstracts.factory;

import com.deft.design.abstracts.util.ClassLoaderUtils;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @author zdl
 * @description
 * @date 2022-04-18
 **/
public class DbInvocationHandler implements InvocationHandler {

    private final IDatabaseAdapter databaseAdapter;

    public DbInvocationHandler(IDatabaseAdapter databaseAdapter) {
        this.databaseAdapter = databaseAdapter;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        return IDatabaseAdapter.class.getMethod(method.getName(), ClassLoaderUtils.getClassByArgs(args)).invoke(databaseAdapter, args);
    }
}
